﻿using System.ComponentModel;
using System.ComponentModel.Design;

namespace Raider.WinForms.Actions.Design
{
    class ActionManagerActionList : DesignerActionList
    {
        public ActionManagerActionList(IComponent component)
            : base(component)
        {
        }

        /// <summary>
        /// Gets or sets a value indicating whether the smart tag panel should 
        /// automatically be displayed when it is created.
        /// </summary>
        public override bool AutoShow
        {
            get { return true; }
            set { }
        }

        /// <summary>
        /// Helper property to acquire an ActionManager reference.
        /// </summary>
        private ActionManager ActionManager
        {
            get { return (ActionManager)Component; }
        }

        /// <summary>
        /// Helper method to acquire a ActionManagerDesigner reference.
        /// </summary>
        private ActionManagerDesigner Designer
        {
            get
            {
                IDesignerHost designerHost = (IDesignerHost)ActionManager.Site.Container;
                return (ActionManagerDesigner)designerHost.GetDesigner(ActionManager);
            }
        }

        public override DesignerActionItemCollection GetSortedActionItems()
        {
            return new DesignerActionItemCollection
			{
                 new DesignerActionMethodItem(this, "EditActions", "Edit Actions...", "Behavior", true),
#if DEBUG
                 new DesignerActionMethodItem(this, "ShowActionMap", "Show Internal Action Map", "Behavior", true),
#endif
			};
        }

        private void EditActions()
        {
            Designer.EditActions();
        }

#if DEBUG
        private void ShowActionMap()
        {
            Designer.ActionManager.ShowTargetActionMap();
        }
#endif

        /// <summary>
        /// Helper method to safely set a component's property.
        /// </summary>
        private void SetProperty(string propertyName, object value)
        {
            PropertyDescriptor property = TypeDescriptor.GetProperties(ActionManager)[propertyName];
            property.SetValue(ActionManager, value);
        }
    }
}
